use std::io;

mod three_door;
mod guessing_game;

fn main() {
    loop {
        info();

        let mut item = String::new();
        let result = io::stdin().read_line(&mut item);
        // result 是一个枚举类型, 它有两个变体, OK 和 Err
        // OK 的 expect 什么都不做，Err 的 expect 触发 panic
        result.expect("Failed to read line");

        let item: u32 = match item.trim().parse() {
            Ok(number) => number,
            Err(_) => {
                println!("Input number please!");
                continue
            },
        };

        match item {
            1 => call1(),
            2 => call2(),
            0 => return,
            _ => println!("Not exercise number."),
        };
        continue;
    }
}

fn info() {
    println!(
"--
Please input exercise number:
  1. guessing game
  2. three door calc
  0. quit"
    );
}

fn call1() {
    // three_door::test();
    println!("this is exercise 1.");
    three_door::main();
}

fn call2() {
    println!("this is exercise 2.");
    guessing_game::guessing_game::main();
}
